//
//  WYCMeWarrantyController.m
//  掌上还
//
//  Created by 李胜军 on 2018/2/6.
//  Copyright © 2018年 中企互联. All rights reserved.
//

#import "WYCMeWarrantyController.h"
#import "WYCArgeeViewController.h"
@interface WYCMeWarrantyController ()
@property(nonatomic,strong)UILabel  *beginTime;//开始时间
@property(nonatomic,strong)UILabel  *endTime;//结束时间

@property(nonatomic,strong)UILabel  *policyNo;
@property(nonatomic,strong)NSString  *state;

@property(nonatomic,strong) UIImageView * stateImage;

@end

@implementation WYCMeWarrantyController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = WYCRGBColor(64, 71, 100);
    [self setupInterface];

    [self setuprequster];

}

- (void)setuprequster{
    NSString * str = [NSString stringWithFormat:@"%@token=%@",usergetUserInsurance,[WYCAccountTool unarchivetoken]];
    WYCLog(@"----------%@",[WYCAccountTool unarchivetoken]);
    [HttpTool POST:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"第一步");
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            
            
            NSDictionary * dict = [responseObject objectForKey:@"result"];
            // 判断对象不为空
            if (dict)
            {
                NSLog(@"进来了");
                [self loadResgsied];
            }
            
    
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}
-(void)loadResgsied
{
    NSString * str = [NSString stringWithFormat:@"%@token=%@",getUserInsurance,[WYCAccountTool unarchivetoken]];
    [HttpTool POST:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"第三步%@",responseObject);
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            [self setuprequsters];

        }else{
            [self showToast:msgStr];
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}
-(void)setuprequsters
{
    NSString * str = [NSString stringWithFormat:@"%@token=%@",usergetUserInsurance,[WYCAccountTool unarchivetoken]];
    WYCLog(@"----------%@",[WYCAccountTool unarchivetoken]);
    [HttpTool POST:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"第一步");
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            
            NSDictionary * dict = [responseObject objectForKey:@"result"];
            
            _beginTime.text = dict[@"beginTime"];
            _endTime.text = dict[@"endTime"];
            _policyNo.text = dict[@"policyNo"];
           
            NSString  *state = [NSString stringWithFormat:@"%@",dict[@"state"]];
            //保障中
            if ([state isEqualToString:@"9"]) {
                _stateImage.image = [UIImage imageNamed:@"baozhang"];
            }
            //待生效
            else if ([state isEqualToString:@"8"]) {
                _stateImage.image = [UIImage imageNamed:@"daishenxiao"];
            }
            //已过期
            else  if ([state isEqualToString:@"10"]) {
                _stateImage.image = [UIImage imageNamed:@"yiguoqi"];
            }
            else
            {
                _stateImage.image = [UIImage imageNamed:@"daishenxiao"];
            }
        }
    
     
     } fail:^(NSURLSessionDataTask *task, NSError *error) {
         
     }];
}
- (void)setupInterface {
    UIView * backview = [[UIView alloc] init];
    backview.frame = CGRectMake(20 * px, NavHeight, ScreenWidth - 40 * px, 40 * px);
    backview.backgroundColor = WYCRGBColor(37,44,71);
    backview.layer.cornerRadius = 10 * px;
    backview.layer.masksToBounds = YES;
    [self.view addSubview:backview];
    
    UIView * interfaceview = [[UIView alloc] init];
    interfaceview.frame = CGRectMake(40 * px, (NavHeight)+20 * px, ScreenWidth - 80 * px, ScreenHeight - (NavHeight) - 20);
    interfaceview.backgroundColor = WYCRGBColor(255,246,233);
    [self.view addSubview:interfaceview];
    
    
    UIImageView * logoimage = [[UIImageView alloc] init];
    logoimage.frame = CGRectMake(ScreenWidth / 2 - 185 * px - 40* px, NavHeight, 370 * px, 91 * px);
    logoimage.image = [UIImage imageNamed:@"warrtylogo"];
    [interfaceview addSubview:logoimage];
    
    
    UILabel * titlelabel = [[UILabel alloc] init];
    titlelabel.frame = CGRectMake(0, CGRectGetMaxY(logoimage.frame) + 80 * px, interfaceview.width, 80 * px);
    titlelabel.text = @"个人资金账户损失险";
    titlelabel.textColor = [UIColor blackColor];
    titlelabel.font = [UIFont systemFontOfSize:70 * px];
    CGAffineTransform matrix = CGAffineTransformMake(1, 0, tanf(-15 * (CGFloat)M_PI / 180), 1, 0, 0);
    titlelabel.transform = matrix;
    titlelabel.textAlignment = NSTextAlignmentCenter;
    [interfaceview addSubview:titlelabel];
    
    
    UILabel *baodanhao = [[UILabel alloc] init];
    baodanhao.frame = CGRectMake(40 * px, CGRectGetMaxY(titlelabel.frame) + 60 * px, 240 * px, 70 * px);
    baodanhao.text = @"保单号";
    baodanhao.font = [UIFont systemFontOfSize:60 * px];
    baodanhao.textColor = [UIColor blackColor];
    [interfaceview addSubview:baodanhao];
    
    
    _policyNo = [[UILabel alloc] init];
    _policyNo.frame = CGRectMake(ScreenWidth-250, CGRectGetMaxY(titlelabel.frame) + 60 * px, 210, 70 * px);
    _policyNo.textAlignment = NSTextAlignmentRight;
    _policyNo.font = [UIFont systemFontOfSize:15];
    _policyNo.textColor = [UIColor blackColor];
    [interfaceview addSubview:_policyNo];
    
    UIView * line = [[UIView alloc] init];
    line.frame = CGRectMake(baodanhao.x, CGRectGetMaxY(baodanhao.frame) + 40 * px, interfaceview.width - 80 * px, 0.5);
    line.backgroundColor = WYCRGBColor(222,222,222);
    [interfaceview addSubview:line];
    
    
    UILabel *baodanduixiang = [[UILabel alloc] init];
    baodanduixiang.frame = CGRectMake(40 * px, CGRectGetMaxY(line.frame) + 60 * px, 280 * px, 70 * px);
    baodanduixiang.text = @"保障对象";
    baodanduixiang.font = [UIFont systemFontOfSize:60 * px];
    baodanduixiang.textColor = [UIColor blackColor];
    [interfaceview addSubview:baodanduixiang];
    
    
    UILabel *baodanduixiangN = [[UILabel alloc] init];
    baodanduixiangN.frame = CGRectMake(ScreenWidth-230, CGRectGetMaxY(line.frame) + 60 * px, 190, 70 * px);
    baodanduixiangN.text = @"被保人名下所有银行卡";
    baodanduixiangN.textAlignment = NSTextAlignmentRight;
    baodanduixiangN.font = [UIFont systemFontOfSize:15];
    baodanduixiangN.textColor = [UIColor blackColor];
    [interfaceview addSubview:baodanduixiangN];
    UIView * duixiangline = [[UIView alloc] init];
    duixiangline.frame = CGRectMake(baodanhao.x, CGRectGetMaxY(baodanduixiang.frame) + 40 * px, interfaceview.width - 80 * px, 0.5);
    duixiangline.backgroundColor = WYCRGBColor(222,222,222);
    [interfaceview addSubview:duixiangline];
    
    
    UILabel *beibaodanhao = [[UILabel alloc] init];
    beibaodanhao.frame = CGRectMake(40 * px, CGRectGetMaxY(duixiangline.frame) + 60 * px, 280 * px, 70 * px);
    beibaodanhao.text = @"被保险人";

    beibaodanhao.font = [UIFont systemFontOfSize:60 * px];
    beibaodanhao.textColor = [UIColor blackColor];
    [interfaceview addSubview:beibaodanhao];
    UILabel *name = [[UILabel alloc] init];
    name.frame = CGRectMake(ScreenWidth-230, CGRectGetMaxY(duixiangline.frame) + 60 * px, 190, 70 * px);
    name.textAlignment = NSTextAlignmentRight;
    name.text = [WYCAccountTool unarchiveuserName];
    name.font = [UIFont systemFontOfSize:15];
    name.textColor = [UIColor blackColor];
    [interfaceview addSubview:name];
    
    UIView * beiline = [[UIView alloc] init];
    beiline.frame = CGRectMake(baodanhao.x, CGRectGetMaxY(beibaodanhao.frame) + 40 * px, interfaceview.width - 80 * px, 0.5);
    beiline.backgroundColor = WYCRGBColor(222,222,222);
    [interfaceview addSubview:beiline];
    
    
    UILabel *startime = [[UILabel alloc] init];
    startime.frame = CGRectMake(40 * px, CGRectGetMaxY(beiline.frame) + 60 * px, 420 * px, 70 * px);
    startime.text = @"保障开始时间";
    startime.font = [UIFont systemFontOfSize:60 * px];
    startime.textColor = [UIColor blackColor];
    [interfaceview addSubview:startime];
    
   _beginTime = [[UILabel alloc] init];
    _beginTime.frame = CGRectMake(ScreenWidth-230, CGRectGetMaxY(beiline.frame) + 60 * px, 190, 70 * px);
    _beginTime.textAlignment = NSTextAlignmentRight;
    _beginTime.font = [UIFont systemFontOfSize:15];
    _beginTime.textColor = [UIColor blackColor];
    [interfaceview addSubview:_beginTime];
    UIView * startimeline = [[UIView alloc] init];
    startimeline.frame = CGRectMake(baodanhao.x, CGRectGetMaxY(startime.frame) + 40 * px, interfaceview.width - 80 * px, 0.5);
    startimeline.backgroundColor = WYCRGBColor(222,222,222);
    [interfaceview addSubview:startimeline];
    
    
    UILabel *endtime = [[UILabel alloc] init];
    endtime.frame = CGRectMake(40 * px, CGRectGetMaxY(startimeline.frame) + 60 * px, 420 * px, 70 * px);
    endtime.text = @"保障结束时间";
    endtime.font = [UIFont systemFontOfSize:60 * px];
    endtime.textColor = [UIColor blackColor];
    [interfaceview addSubview:endtime];
    _endTime = [[UILabel alloc] init];
    _endTime.frame = CGRectMake(ScreenWidth-230, CGRectGetMaxY(startimeline.frame) + 60 * px, 190, 70 * px);
    _endTime.textAlignment = NSTextAlignmentRight;
    _endTime.font = [UIFont systemFontOfSize:15];
    _endTime.textColor = [UIColor blackColor];
    [interfaceview addSubview:_endTime];
    
    UIView * endtimeline = [[UIView alloc] init];
    endtimeline.frame = CGRectMake(baodanhao.x, CGRectGetMaxY(endtime.frame) + 40 * px, interfaceview.width - 80 * px, 0.5);
    endtimeline.backgroundColor = WYCRGBColor(222,222,222);
    [interfaceview addSubview:endtimeline];
    
    
    UILabel *rexian = [[UILabel alloc] init];
    rexian.frame = CGRectMake(40 * px, CGRectGetMaxY(endtimeline.frame) + 60 * px, 280 * px, 70 * px);
    rexian.text = @"服务热线";
    rexian.font = [UIFont systemFontOfSize:60 * px];
    rexian.textColor = [UIColor blackColor];
    [interfaceview addSubview:rexian];
    
    UILabel *rexian1 = [[UILabel alloc] init];
    rexian1.frame = CGRectMake(ScreenWidth-230, CGRectGetMaxY(endtimeline.frame) + 60 * px, 190, 70 * px);
    rexian1.text = @"95505";
    rexian1.textAlignment = NSTextAlignmentRight;
    rexian1.font = [UIFont systemFontOfSize:15];
    rexian1.textColor = [UIColor blackColor];
    [interfaceview addSubview:rexian1];
    UIView * rexianline = [[UIView alloc] init];
    rexianline.frame = CGRectMake(baodanhao.x, CGRectGetMaxY(rexian.frame) + 40 * px, interfaceview.width - 80* px, 0.5);
    rexianline.backgroundColor = WYCRGBColor(222,222,222);
    
    [interfaceview addSubview:rexianline];
    
    _stateImage = [[UIImageView alloc] init];
    _stateImage.frame = CGRectMake(ScreenWidth-150, ScreenHeight-120, 120, 100);
    _stateImage.image = [UIImage imageNamed:@"yiguoqi"];
    [self.view addSubview:_stateImage];
    
    
    
    //用户须知的按钮
    UIButton * userAgreement = [[UIButton alloc] init];
    [userAgreement setTitle:@"《免责协议》" forState:UIControlStateNormal];
    userAgreement.titleLabel.font = [UIFont systemFontOfSize:43 * px];
    userAgreement.frame = CGRectMake(ScreenWidth/2-50, ScreenHeight-50, 120, 30);
    userAgreement.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [userAgreement setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [userAgreement addTarget:self action:@selector(pressxieyi) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:userAgreement];
    UIImageView * juchiimage = [[UIImageView alloc] init];
    juchiimage.frame = CGRectMake(interfaceview.x, CGRectGetMaxY(interfaceview.frame), interfaceview.width, 20);
    juchiimage.image = [UIImage imageNamed:@"juchi"];
    [self.view addSubview:juchiimage];
    
    
}
-(void)pressxieyi
{
    WYCArgeeViewController  *agreeView = [[WYCArgeeViewController alloc]init];
    [self.navigationController pushViewController:agreeView animated:YES];
}
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    
    
    self.navigationController.navigationBar.hidden = YES;
    
    
    UIView * NavView = [[UIView alloc] init];
    NavView.frame = CGRectMake(0, 0, ScreenWidth, NavHeight);
    NavView.backgroundColor = WYCRGBColor(64, 71, 100);
    [self.view addSubview:NavView];
    
    
    
    CALayer *bottomLineLayer = [[CALayer alloc] init];
    bottomLineLayer.frame = CGRectMake(0, NavView.bounds.size.height - 0.5, NavView.bounds.size.width, 0.5);
    bottomLineLayer.backgroundColor = WYCRGBColor(64, 71, 100).CGColor;
    [NavView.layer addSublayer:bottomLineLayer];
    
    //返回按钮
    UIButton *  fanhuibutton = [[UIButton alloc] init];
    [fanhuibutton setImage:[UIImage imageNamed:@"Nav_back"] forState:UIControlStateNormal];
    [fanhuibutton addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    fanhuibutton.frame = CGRectMake(30 * px, titleY, 66 * px , 66 * px);
    [NavView addSubview:fanhuibutton];
    
    
    UILabel * NavRigsterLabel = [[UILabel alloc] init];
    NavRigsterLabel.frame = CGRectMake(0, titleY, NavView.width, 68 * px);
    NavRigsterLabel.textColor = [UIColor whiteColor];
    NavRigsterLabel.font = [UIFont boldSystemFontOfSize:BigFont];
    NavRigsterLabel.textAlignment = NSTextAlignmentCenter;
    NavRigsterLabel.text = @"我的保单";
    [NavView addSubview:NavRigsterLabel];
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:YES];
}

@end
